package com.wang.cloud.manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.wang.cloud.common.core.api.ApiResult;
import com.wang.cloud.manage.domain.co.*;
import com.wang.cloud.manage.domain.vo.SysUserDetailVo;
import com.wang.cloud.manage.domain.vo.SysUserPageVo;
import com.wang.cloud.manage.service.manage.SysUserManage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统平台用户信息表 前端控制器
 * </p>
 *
 * @author wy
 * @since 2024-07-16
 */
@Tag(name = "系统用户-管理")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/manage/sys/user")
public class SysUserController {

    private final SysUserManage sysUserManage;

    @Operation(summary = "分页查询")
    @GetMapping("page")
    public ApiResult<IPage<SysUserPageVo>> page(PlatformUserPageCo pageCo) {
        return ApiResult.success(sysUserManage.page(pageCo));
    }

    @Operation(summary = "获取详情")
    @GetMapping("info")
    public ApiResult<SysUserDetailVo> detailInfo(@RequestParam Long id) {
        return ApiResult.success(sysUserManage.detailInfo(id));
    }

    @Operation(summary = "新增")
    @PostMapping("add")
    public ApiResult<Long> add(@Validated @RequestBody SysUserAddCo addCo) {
        Long id = sysUserManage.addSysUser(addCo);
        return ApiResult.success(id);
    }

    @Operation(summary = "更新")
    @PostMapping("update")
    public ApiResult update(@Validated @RequestBody SysUserUpdateCo updateCo) {
        sysUserManage.updateSysUser(updateCo);
        return ApiResult.success();
    }

    @ApiOperationSupport(order = 7)
    @Operation(summary = "更新-用户状态")
    @PostMapping("status/update")
    public ApiResult<Boolean> updateStatus(@Validated @RequestBody UpdateStatusCo co) {
        Boolean result = sysUserManage.updateSysUserStatus(co);
        return ApiResult.success(result);
    }

    @ApiOperationSupport(order = 14)
    @Operation(summary = "重置用户密码")
    @PostMapping("pwd/rest")
    public ApiResult<String> restPwd(@Validated @RequestBody SysUserRestPwdCo co) {
        sysUserManage.restSysUserPwd(co);
        return ApiResult.success("成功");
    }

    @Operation(summary = "删除")
    @DeleteMapping("del")
    public ApiResult del(@RequestParam Long id) {
        sysUserManage.delSysUser(id);
        return ApiResult.success();
    }
}
